package com.speechb.controller.admin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.speechb.controller.base.BaseController;
import com.speechb.entity.LoginHistory;
import com.speechb.service.ILoginHistoryService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 登录历史记录
 *
 * @author : llj
 * @version :2.1.0
 * @date : 2021/2/2 22:41
 */
@RestController
@RequestMapping("${adminRoot}/login_history")
public class LoginHistoryAdminController extends BaseController {
    private final static Logger LOGGER = LoggerFactory.getLogger(LoginHistoryAdminController.class);

    @Autowired
    ILoginHistoryService loginHistoryService;

    @GetMapping("/list")
    @ResponseBody
    public void ordersList(){
        Integer pageNum = getPageNum();
        Integer pageSize = Integer.parseInt(getPara("page_size","0"));
        String order = getPara("order");
        String search = getPara("search");
        if (StringUtils.isNotEmpty(search)) {
            search = "%"+search+"%";
        }
        Page<Object> objects = PageHelper.startPage(pageNum, pageSize, true);
        List<LoginHistory> listOfAdmin = loginHistoryService.findListOfAdmin(order,search);
        writeData(listOfAdmin,(int)objects.getTotal());
    }
}
